import {Injectable }from '@angular/core'; 
import {HttpClient, HttpHeaders }from '@angular/common/http'; 
import "rxjs/add/operator/map"; 
// import { AppConfig } from '../app/app.config';
import { UtilsService } from './utils.service';

const httpOptions =  {
  headers:new HttpHeaders( {
      "Accept":"application/json", 
      "Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"})
}; 

@Injectable()
export class HttpsService {
    utils:UtilsService; //工具类

    constructor(public http:HttpClient) {
        console.log('Hello HttpsProvider Provider'); 
    }
    //get请求
    get(url:string, params:any, successCallback, errorCallback):any {
        this.http.get(url, httpOptions).subscribe(res =>  {
            // console.log("res==="+res);
            successCallback && successCallback(res); 
        }, err =>  {
            errorCallback && errorCallback(err); 
        }); 
    }
    post(url:string, params:any, successCallback, errorCallback):any {
        // let hotMoviesUrl:string = "http:/访问项目的ip/myapp/login"; 
        // params = '{"user": "测试1"}'
        this.http.post(url, params, httpOptions).subscribe(res =>  {
            successCallback && successCallback(res); 
        }, err =>  {
            errorCallback && errorCallback(err); 
        }); 
    }
   
}